﻿//--------------------------------------------------------------------//
//	   此代码由代码生成器自动生成									  //
//	   生成时间 2021-05-19 14:37:28 	                              //
//	   描述：库存盘点表
//--------------------------------------------------------------------//

using System;
using System.Collections.Generic;
using System.Linq;
using FluentValidation;
using RayD.Core;

namespace RayD.WebApi.Models.Interact
{
    public class RX_AdjustmentModel : BaseModel
    {
        #region 实体成员
        /// <summary>
        /// 海关：PREENTRYNO 录入编号
        /// </summary>
        /// <returns></returns>
        public string Preentryno { get; set; }
        /// <summary>
        /// 海关：DCLTYPECD 申报类型代码1-备案/申请、3-作废。（仅用于申报库，执法库没有此字段 ）
        /// </summary>
        /// <returns></returns>
        public string Dcltypecd { get; set; }

        /// <summary>
        /// 海关：COPCODE 企业编号
        /// </summary>
        /// <returns></returns>
        public string Copcode { get; set; }
        /// <summary>
        /// 海关：COPNAME 企业名称
        /// </summary>
        /// <returns></returns>
        public string Copname { get; set; }
        /// <summary>
        /// 海关：SHOPID 免税店/监管仓库编号公服：warehouseId　仓库\⻔店唯⼀标识
        /// </summary>
        /// <returns></returns>
        public string Shopid { get; set; }
        /// <summary>
        /// 海关：SHOPNAME 免税店/监管仓库名称公服：warehouseName　仓库\⻔店名称
        /// </summary>
        /// <returns></returns>
        public string Shopname { get; set; }
        /// <summary>
        /// 海关：APPTIME 申请日期 日期格式“yyyy-MM-dd HH:mm:ss公服：applyTime 申报时间，可以传毫秒类型的unix 时间戳，或者传 yyyy-MM-dd HH:mm:ss 格式的字符串
        /// </summary>
        /// <returns></returns>
        public DateTime Apptime { get; set; }
        /// <summary>
        /// 海关：CUSTOMSID 主管海关
        /// </summary>
        /// <returns></returns>
        public string Customsid { get; set; }
        /// <summary>
        /// 海关：申请人姓名
        /// </summary>
        /// <returns></returns>
        public string Udper { get; set; }
        /// <summary>
        /// 海关：OPTYPE 01盘亏02销毁03其他(Reason不能为空)公服：BILLTYPE 业务类型 1-店⾯盘亏 2-免税监管仓盘亏 3-销毁 4-⻔店盘盈 5-免税监管仓盘盈 0-其他（Reason不能为空）
        /// </summary>
        /// <returns></returns>
        public string Optype { get; set; }
        /// <summary>
        /// 公服：调整原因
        /// </summary>
        /// <returns></returns>
        public string Reason { get; set; }
        /// <summary>
        /// 公服：操作人员账号
        /// </summary>
        /// <returns></returns>
        public string Inputer { get; set; }
        /// <summary>
        /// 订单编号 订单编号长 度不能超过60位。
        /// </summary>
        /// <returns></returns>
        public string Orderno { get; set; }

        /// <summary>
        /// 单据明细
        /// </summary>
        public List<RX_AdjustmentListModel> List { get; set; }
        #endregion

        /// <summary>
        /// 业务参数验证
        /// </summary>
        /// <returns></returns>
        public override (bool, string) CheckParameter()
        {
            //表头验证
            var (isSuccess, msg) = base.CheckParameter(new RX_AdjustmentModelValidator().Validate(this));
            if (!isSuccess)
            {
                return (false, msg);
            }
            //明细验证
            if (List.Length() > 0)
            {
                foreach (var item in List)
                {
                    (isSuccess, msg) = item.CheckParameter();
                    if (!isSuccess)
                    {
                        return (false, msg);
                    }
                }
            }
            return (isSuccess, msg);
        }

    }

    /// <summary>
    /// 模型验证
    /// </summary>
    public class RX_AdjustmentModelValidator : AbstractValidator<RX_AdjustmentModel>
    {
        public RX_AdjustmentModelValidator()
        {
            //RuleFor(x => x.Surname).NotEmpty();
            //RuleFor(x => x.Forename).NotEmpty().WithMessage("Please specify a first name");
            //RuleFor(x => x.Discount).NotEqual(0).When(x => x.HasDiscount);
            //RuleFor(x => x.Address).Length(20, 250);
            //RuleFor(x => x.Postcode).Must(BeAValidPostcode).WithMessage("Please specify a valid postcode");

            RuleFor(x => x.Preentryno).NotEmpty().WithMessage("录入编号不能为空！");
            RuleFor(x => x.Dcltypecd).NotEmpty().WithMessage("申报类型不能为空！");
            RuleFor(x => x.Copcode).NotEmpty().WithMessage("企业编号不能为空！");
            RuleFor(x => x.Copname).NotEmpty().WithMessage("企业名称不能为空！");
            RuleFor(x => x.Shopid).NotEmpty().WithMessage("免税店/监管仓库编号不能为空！");
            RuleFor(x => x.Shopname).NotEmpty().WithMessage("免税店/监管仓库名称不能为空！");
            RuleFor(x => x.Apptime).NotEmpty().WithMessage("申报时间不能为空！");
            RuleFor(x => x.Customsid).NotEmpty().WithMessage("主管海关不能为空！");
            RuleFor(x => x.Udper).NotEmpty().WithMessage("申请人姓名不能为空！");
            RuleFor(x => x.Orderno).NotEmpty().WithMessage("单据编号不能为空！");
            //RuleFor(x => x.List).Must(ValidateList).WithMessage("明细有误！");
        }

        //private bool ValidateList(List<RX_AdjustmentListModel> list)
        //{
        //    bool res = true;
        //    foreach (var item in list)
        //    {
        //        var (isSuccess, msg) = item.CheckParameter();
        //        res = isSuccess;
        //    }
        //    return res;
        //}
    }
}

